Walkthrough 11-7: Define and use custom data types

In this walkthrough, you continue to work with the flight JSON posted to the flow. You will:

·       Define and use custom data types.

·       Transform objects to POJOs.

Starting file

If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the solutions folder of the student files ZIP located in the Course Resources.

Define a custom data type

1.     Return to the Transform Message properties view for the transformation in postMultipleFlights.

2.     Select and cut the string formatting expression for the prices.

3.     In the header section of the expression, define a custom data type called Currency.

4.     Set it equal to the value you cut.

type Currency = String {format: "###.00"}

 

Use a custom data type

5.     In the DataWeave expression, set the price to be of type currency.

price: object.price as Number as Currency,

6.     Look at the preview; the prices should still be formatted as strings to two decimal places.

Transform objects to POJOs

7.     Open the Flight.java class in the project's src/main/java folder, look at the names of the properties then close the file.

  

8.     Return to the Transform Message properties view for the transformation in postMultipleFlights.

9.     In the header section of the expression, define a custom data type called Flight that is of type com.mulesoft.training.Flight.

type Flight = Object {class: "com.mulesoft.training.Flight"}

10.  In the DataWeave expression, set the map objects to be of type Flight.

11.  Look at the preview.

12.  Change the output type from application/dw to application/java.

13.  Look at the issues you get.

 

14.  Change the name of the dest key to destination.

destination: object.destination,

15.  Change the other keys to match the names of the Flight class properties:

·       plane to planeType

·       date to departureDate

16.  Comment out the totalSeats property.

17.  Look at the preview.

 

Note: If you want to test the application with Advanced REST Client, be sure to change the content-type header to application/xml and replace the request body with XML from the flights-example.xml file.

 



Did you complete the walkthrough?

  Yes, I completed the walkthrough

  No, I did not complete the walkthrough

  I completed part of the walkthrough


Comments and/or feedback